package br.com.empresa.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import be.com.empresa.modelo.Cliente;
import be.com.empresa.modelo.Produto;
import br.com.empresa.dao.ClienteDAO;
import br.com.empresa.dao.ProdutoDAO;

public class CadastroClienteGUI extends JFrame {

	private JPanel contentPane;
	private JTextField txCodigo;
	private JTextField txNome;
	private JTextField txRg;
	private JTextField txCpf;
	private JTextField txTelefone;
	private JTextField txEmail;
	private DefaultTableModel modelo;
	private int linhaSelecionada;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadastroClienteGUI frame = new CadastroClienteGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadastroClienteGUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 786, 574);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(Color.BLACK);
		panel_1.setBounds(0, 0, 760, 35);
		panel.add(panel_1);
		
		JLabel lblProduto = new JLabel("CLIENTES");
		lblProduto.setForeground(Color.WHITE);
		panel_1.add(lblProduto);
		
		JPanel panel_2 = new JPanel();
		panel_2.setBackground(Color.BLACK);
		panel_2.setBounds(0, 494, 760, 32);
		panel.add(panel_2);
		panel_2.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("Desenvolvido por Andr\u00E9 dos Santos");
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setBackground(Color.WHITE);
		lblNewLabel.setBounds(568, 11, 182, 14);
		panel_2.add(lblNewLabel);
		
		JLabel lblCdigo = new JLabel("C\u00F3digo:");
		lblCdigo.setBounds(10, 46, 46, 14);
		panel.add(lblCdigo);
		
		JLabel lblNome = new JLabel("Nome:");
		lblNome.setBounds(290, 46, 97, 14);
		panel.add(lblNome);
		
		JLabel lblPreo = new JLabel("RG:");
		lblPreo.setBounds(10, 71, 97, 14);
		panel.add(lblPreo);
		
		JLabel lblFornecedor = new JLabel("CPF:");
		lblFornecedor.setBounds(290, 71, 59, 14);
		panel.add(lblFornecedor);
		
		txCodigo = new JTextField();
		txCodigo.setBounds(117, 46, 66, 14);
		panel.add(txCodigo);
		txCodigo.setColumns(10);
		
		txNome = new JTextField();
		txNome.setColumns(10);
		txNome.setBounds(386, 46, 321, 14);
		panel.add(txNome);
		
		txRg = new JTextField();
		txRg.setColumns(10);
		txRg.setBounds(117, 71, 152, 14);
		panel.add(txRg);
		
		JButton btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Cliente cliente = new Cliente();
				cliente.setNome(txNome.getText());
				cliente.setTelefone(txTelefone.getText());
				cliente.setRg(txRg.getText());
				cliente.setCpf(txCpf.getText());
				cliente.setEmail(txEmail.getText());
				ClienteDAO dao = new ClienteDAO();
					dao.inserir(cliente);	
				dispose();
			}
		});
		btnSalvar.setBounds(562, 460, 89, 23);
		panel.add(btnSalvar);
		
		JButton btnLimpar = new JButton("Limpar");
		btnLimpar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnLimpar.setBounds(661, 460, 89, 23);
		panel.add(btnLimpar);
		
		txCpf = new JTextField();
		txCpf.setColumns(10);
		txCpf.setBounds(386, 71, 95, 14);
		panel.add(txCpf);
		
		JLabel lblInscrioEstadual = new JLabel("E-mail");
		lblInscrioEstadual.setBounds(10, 96, 105, 14);
		panel.add(lblInscrioEstadual);
		
		JLabel lblCnpj = new JLabel("Telefone:");
		lblCnpj.setBounds(290, 96, 59, 14);
		panel.add(lblCnpj);
		
		txTelefone = new JTextField();
		txTelefone.setColumns(10);
		txTelefone.setBounds(386, 96, 95, 14);
		panel.add(txTelefone);
		
		txEmail = new JTextField();
		txEmail.setColumns(10);
		txEmail.setBounds(117, 96, 152, 14);
		panel.add(txEmail);
		
		JLabel Marca = new JLabel("Marca:");
		Marca.setBounds(10, 127, 105, 14);
		panel.add(Marca);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(117, 121, 152, 20);
		panel.add(comboBox);
		
		JButton button = new JButton("Voltar");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Menu menu = new Menu ();
				menu.setVisible(true);
				dispose();
			}
		});
		button.setBounds(463, 460, 89, 23);
		panel.add(button);
	}

}
